package edu.pku.dao;

import java.sql.SQLException;
import java.util.List;

import com.ibatis.sqlmap.client.SqlMapClient;

import edu.pku.data.ProductCategory;
import edu.pku.util.MySqlMapClient;

public class ProductCategoryDao {
	
	public void addProductCategory(ProductCategory pc) throws SQLException
	{
		SqlMapClient sqlMap = MySqlMapClient.getSqlMapInstance();
		sqlMap.insert("insert_product_category",pc);
	}
	
	public boolean isNameExist(String companyName,String name) throws SQLException
	{
		SqlMapClient sqlMap = MySqlMapClient.getSqlMapInstance();
		List<String> list = sqlMap.queryForList("get_product_category_name",companyName);
		if(list.contains(name))
			return true;
		return false;
	}
	
	public List<ProductCategory> getProductCategorys(String companyName) throws SQLException
	{
		SqlMapClient sqlMap = MySqlMapClient.getSqlMapInstance();
		List<ProductCategory> list =  sqlMap.queryForList("get_product_category",companyName);
		return list;
	}
	
	public void deleteProductCategory(ProductCategory pc) throws SQLException
	{
		SqlMapClient sqlMap = MySqlMapClient.getSqlMapInstance();
		sqlMap.delete("delete_product_category",pc);
	}
	
	public void updateProductCategory(ProductCategory pc) throws SQLException
	{
		SqlMapClient sqlMap = MySqlMapClient.getSqlMapInstance();
		sqlMap.update("update_product_category",pc);
	}
}
